package com.estar.integaration.Util;

import com.estar.integaration.entity.paymentPlanEntity.SupplierAccountPeriod;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

/**
 * Author: YJL
 * Date: 2022/3/25 23:52
 **/
public class DateComparatorAsc implements Comparator<SupplierAccountPeriod> {

  @Override
  public int compare(SupplierAccountPeriod o1, SupplierAccountPeriod o2) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/M/dd");
    try {
      Date d1 = sdf.parse(o1.getSupplierName());
      Date d2 = sdf.parse(o2.getSupplierName());
      long time1 = d1.getTime();
      long time2 = d2.getTime();
      if(time1 == time2) {
        return 0;
      }else {
        if(d1.after(d2)){
          return 1;
        }else{
          return -1;
        }
      }
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return 0;
  }

  @Override
  public Comparator<SupplierAccountPeriod> reversed() {
    return null;
  }

}
